package com.test.resumeanalysis.common

import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding

// 文件名 CommonRvAdapter.kt
/**
 * @description: recyclerView的Adapter的简单封装, 仅针对单类型viewType
 *
 * @param E: 列表数据实体类
 * @param V: item的xml文件对应的Binding类
 **/
abstract class CommonRvAdapter<E : Any, V : ViewBinding> : RecyclerView.Adapter<CommonRvHolder<V>>() {
    /**
     * 数据源
     */
    open var data: MutableList<E> = mutableListOf()
        set(value) {
            field = value
            notifyItemRangeChanged(0, value.size)
        }


    abstract override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CommonRvHolder<V>

    override fun getItemCount(): Int = data.size

    override fun onBindViewHolder(holder: CommonRvHolder<V>, position: Int) {
        onBindViewHolder(holder, holder.adapterPosition, holder.binding, data[holder.adapterPosition])
    }

    abstract fun onBindViewHolder(holder: CommonRvHolder<V>, position: Int, binding: V, bean: E)
}

open class CommonRvHolder<V : ViewBinding>(val binding: V) : RecyclerView.ViewHolder(binding.root) {

}

